import webbrowser
import os
import psutil
import pyautogui,pyscreeze
from PIL import Image
from time import time


class SystemInfo:
    boot_time = 0 #开机时间(s)
    cpu_usage = 0 #CPU占用率(%)
    ram_usage = 0 #运行内存占用率(%)
    disk_usage = 0 #C盘占用率(%)
    def __init__(self, boot_time,cpu_usage=0, ram_usage=0, disk_usage=0):
        self.boot_time = boot_time
        self.cpu_usage = cpu_usage
        self.ram_usage = ram_usage
        self.disk_usage = disk_usage
    def print(self):
        print(self.boot_time,self.cpu_usage,self.ram_usage,self.disk_usage)

def open_Website(url:str):
    webbrowser.open(url)
def open_File(filepath:str):
    os.system(f"start {filepath}")
def get_System_Info()->SystemInfo:
    try:
        disk = psutil.disk_usage("F:\\").percent
    except FileNotFoundError:
        disk = 0
    info = SystemInfo(int(time()-psutil.boot_time()),psutil.cpu_percent(interval=0.5)*10,psutil.virtual_memory().percent,disk)
    return info
def get_System_Screenshot(region:tuple[int,int,int,int]|None)->Image:
    return pyautogui.screenshot(region=region)
